import 'package:flutter/material.dart';

class TabbarDemo extends StatefulWidget {
  const TabbarDemo({Key? key}) : super(key: key);

  @override
  _TabbarDemoState createState() => _TabbarDemoState();
}

class _TabbarDemoState extends State<TabbarDemo> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SampleTabbar(),
    );
  }
}

class SampleTabbar extends StatefulWidget {
  const SampleTabbar({Key? key}) : super(key: key);

  @override
  _SampleTabbarState createState() => _SampleTabbarState();
}

class _SampleTabbarState extends State<SampleTabbar>
    with SingleTickerProviderStateMixin {
  TabController? _tabController;

  List<Tab> tabs = <Tab>[
    Tab(text: 'Zeroth'),
    Tab(text: 'First'),
    Tab(text: 'Second'),
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Tabbar Demo"),
        centerTitle: true,
        bottom: TabBar(
          tabs: tabs,
          controller: _tabController,
        ),
      ),
      // body: TabBarView(children: tabs,controller: _tabController,),
      body: TabBarView(
        children: tabs.map((e) {
          return Center(
            child: Text(
              "${e.text!.toUpperCase()}",
              style: TextStyle(fontSize: 36),
            ),
          );
        }).toList(),
        controller: _tabController,
      ),
    );
  }
}
